#This is my replication code. If you have any questions, you should probably get a refresher in R.

setwd("C:\\Users\\Aaron\\Dropbox\\Dafoe Replication")
data = read.csv("rep_data.csv")
colnames(data) = c("title", "should", "are", "request", "paper.cites", "priorpubs", "priorcites", "author", "year")
data$are = as.character(data$are)
data$request = as.character(data$request)


data$are[data$are=="Yes"] = 1
data$are[data$are=="No"] = 0
data$request[data$request=="Yes"] = 1
data$request[data$request=="No"] = 0
data$year = as.numeric(data$year) - min(as.numeric(data$year))

data$avgcites = data$priorcites/data$priorpubs
is.na(data$avgcites) = 0

data$logcites = log(data$priorcites)
data$logcites[data$logcites == -Inf] = 0
data$logpubs = log(data$priorpubs)
data$logpubs[data$logpubs == -Inf] = 0

data$logavgcites = data$logcites/data$logpubs
is.na(data$logavgcites) = 0

m0 = lm(paper.cites ~ are, data=data)
m1 = lm(paper.cites ~ are + logcites, data=data)
m2 = lm(paper.cites ~ are + year, data=data)
m3 = lm(paper.cites ~ are + year + logcites, data=data)


library(stargazer)
stargazer(m0, m1, m2, m3, title = "Publishing Replication Files Corresponds to Lower Citation Counts",
          dep.var.labels = c("Citation Count"))